<template>
  <div class="container" v-title data-title="活动详情">
    <div class="activities">
      <div class="thumbnail" >
        <img :src="require('../styles/asset/coupon/ACoolSummer1.jpg')">
      </div>
      <div class="thumbnail" >
        <a class="submit-btn" @click="getCoupon()"></a>
        <img :src="require('../styles/asset/coupon/ACoolSummer2.png')">
      </div>
    </div>
    <simplert ref="simplert"></simplert>
  </div>
</template>

<script>
  import Simplert from '../../components/dialog/dialog.vue';
  import wx from 'weixin-js-sdk'

  export default {
    data () {
      return {
        token:"",
        id:"",
        state:false,
        img: require('../styles/asset/share.jpg'),
        wx_app:''
      }
    },
    created () {

    },
    mounted(){
      const that = this;
      const url = window.location.href;
      this.id = this.$util.parseURL(url).params.id;
      if(url.indexOf('wx_app')>0){
        this.wx_app = this.$util.parseURL(url).params.wx_app;
        this.detail = this.$util.parseURL(url).params.detail;
      }else{
        this.wx_app = ''
      }
      this.$util.getUserToken().then(token=>{
        that.token = token;
      })
      let root = process.env.MAIN_ROOT
      // console.log(root+this.img)
      this.$util.sendShareMessage("每日领取优惠券","活动期间，优惠券持续发放中", root+this.img,url);

      if(url.indexOf('wx_app')>0){
        let newUrl = this.$util.wxUrl(url);
        // 小程序分享title，url
        wx.miniProgram.postMessage({
          data: {
            title: '清凉一夏送骑行劵活动',
            wx_url: newUrl
          }
        })
      }
    },
    components: {
      Simplert
    },
    methods: {
      open (title, message, type) {
        let obj = {
          title: title,
          message: message,
          type: type
        }
        this.$refs.simplert.openSimplert(obj)
      },
      getCoupon () {
        let that = this;
        if(!this.wx_app){
          this.$util.download(that.token);
        }
        if(!this.token || this.token == undefined || this.token == ""){
          return false;
        }
        this.$api.post('/coupon/v1/authApi/getActivityCoupon?id='+this.id,{},s=>{
          this.open('优惠券发放成功','','fade_success');
          this.state = true;
        },f=>{
          this.open(f.errorMessage,'','fade_alert');
        },{
          'requestPlatform': that.wx_app,
          'token': that.token
        })

      }
    }
  }
</script>

<style scoped >
  @import "../styles/styles.css";
  .thumbnail{ padding: 0; margin: 0;}
  .thumbnail>img{ width: 100%;}
  .container{ position: relative; width: 100%; }
  .activities{ overflow-y: scroll;  }
  ul.myul{ padding-bottom: 1rem;}
  ul.myul>li{ position:relative; padding: 1rem; position: relative; padding-left: 3rem; color:#666;}
  ul.myul>li:after{ content: ""; position: absolute; display:block; left: 1.5rem; top: 1.4rem;  width: 0.5rem; height: 0.5rem; border: 2px solid rgba(245,205,125,1); border-radius: 50%;}
  .submit-btn{display: inline-block;position:absolute;left:4.8rem;z-index:100; width:2.2rem;height:2.2rem; margin:0 auto; }
</style>
